import random
randnum = random.randint(1,100)

count = 0
money = 5000
print("你有%d金币" % money)
while True:
    if money < 500:
        break
    count = count + 1
    guess = input("第%d次猜测，请输入一个1~100的整数: " % count)

    if not guess.isdigit():
        print("请输入整数")
    elif int(guess) <1 or int(guess) >100:
        print("要输入1~100之间的整数")
    elif int(guess) > randnum:
        money = money-500
        print("猜的数字大了,金币余额%d" % money)
    elif int(guess) < randnum:
        money = money - 500
        print("猜的数字小了金币余额%d" % money)
    else:
        money = money + 3000
        print("恭喜猜中，金币余额%d" % money)
        goon = input("是否继续游戏(1继续，0退出):")
        if int(goon) == 1:
            randnum = random.randint(1, 100)

            count = 0
        else:break

